<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src='src1/icreate.core.js'></script>
     	<script src='src1/icreate.dom.js'></script>
     	<style>
	     	div {
	            border: 1px dashed red;
	            height: 200px;
	            margin: 10px 0;
	        }
	        div>p {
	            border: 1px solid blue;
	            margin: 10px 0;
	        }
	        .c {
	            background-color: green;
	        }

     	</style>
    </head>
    <script>
    var arr=[],
    	push=arr.push;

    	Icreate.prependChild = function( currentNode, parentNode ){
    		if( parentNode.childNodes.length == 0 ){
    			parentNode.appendChild(currentNode);
    		}else{
    			parentNode.insertBefore( currentNode, parentNode.firstChild );
    		}
    	};
    	Icreate.fn.prependTo = function ( selector ) {
    		var iObj =this.constructor( selector );
    		//统一变成伪数组了
            // this 是 伪数组, iObj 也是伪数组, 将 this 中的每一个元素, 加到 iObj 中的每一个元素里
            var tmp =[], tmpNode;
            for(var i=0;i<this.length;i++){
            	for(var j=0;j<iObj.length;j++){
            		tmpNode = j == iObj.length - 1 ? this[i]: this[i].cloneNode(true);
            		tmp.push(tmpNode);

            		Icreate.prependChild( tmpNode, iObj[j]);
            	}
            }
            // 返回的是一个新的 jq 对象, 用 tmp 中的元素组成
            var tmpIobj = this.constructor();
            tmpIobj.prevObject = this;
            push.apply( tmpIobj, tmp );
            return tmpIobj;
    	}

    	Icreate.fn.prepend = function( selector ){
    		this.constructor( selector ).prependTo(this);
    		return this;
    	}



    </script>
    <body>
	    <div><p>ppp</p></div>
	    <div><p>ppp</p></div>
	    <div><p>ppp</p></div>
    </body>
    <script>
    	var p1=I('<p>ppp1</p><p>ppp2</p>')
    	p1.prependTo('div').each(function(){
    		this.className ='c';
    	});

    </script>
</html>